package aic.ws;

import aic.beans.Customer;
import aic.faults.*;
import aic.lists.CustomerList;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jws.WebService;

@WebService(portName = "NotificationPT", endpointInterface = "aic.ws.MailService", serviceName = "NotificationService")
public class MailServiceImpl implements MailService {

    public Boolean notify_customer(Customer customer, String message) {
        if (!CustomerList.contains(customer)) {
            UnknownCustomerFault ucf = UnknownCustomerFaultFactory.createSOAPUnknownCustomerFault("http://bittschen.net/OrderManagementService/place_order", customer);
            throw ucf;
        }
        
        try {
            Thread.sleep(30 * 1);//000);
        } catch (InterruptedException ex) {}
        
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");

        System.out.println("[MailService] " + new Date() + " :: " + customer.getName());
        System.out.println("[MailService] Sending message :: " + message);
        System.out.print("[MailService] Success :: ");

        if (Math.random() < Double.parseDouble("0.5")) {
            System.out.println("true");
            return true;
        } else {
            System.out.println("false");
            return false;
        }
    }
}
